<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color: #fcfcfc;
            margin: 0;
            padding: 0;
        }

        .qiu {
            display: flex;
        }

        .qiu div {
            margin-right: 5px;
        }

        .qiu-item {
            width: 29px;
            height: 29px;
            line-height: 29px;
            border-radius: 50%;
            margin-bottom: 0;
            color: #fff;
            text-align: center;
        }

        /* 设置div背景渐变色 中心到两端 从 红颜色变淡 有立体效果*/
        .qiu-item-wqgg-zjhm-red {
            background: linear-gradient(to right, #ff0000, #ff9900);

        }

        .qiu-item-wqgg-zjhm-blue {
            background: linear-gradient(to right, #0000ff, #0099ff);
        }

        /* 添加响应式容器 */
        .table-container {
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            margin: 0 auto;
            text-align: center;
        }

        table {
            border-collapse: collapse;
            text-align: center;
            margin: auto;
            width: 100%;
            max-width: 1180px;
        }

        thead tr {
            background-color: #f2f2f2;
        }

        tbody tr:nth-child(odd) {
            background-color: #fef3f3f3;
            /* 奇数行颜色 */
        }

        tbody tr:hover {
            background-color: #b9daf5;
            /* 奇数行颜色 */
        }

        th,
        td {
            border: 1px solid #e4dbdb;
            padding: 6px 15px;
        }

        #input-period {
            padding: 8px 12px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 14px;
            outline: none;
            width: 400px;
        }

        #btn-search {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            background-color: #007bff;
            color: #fff;
            font-size: 14px;
            cursor: pointer;

        }

        #btn-search:hover {
            background-color: #0056b3;
        }

        #result {
            display: inline-block;
            margin: 10px;
            font-size: 14px;
            color: #333;

        }

        /* 响应式设计：在小屏幕上调整样式 */
        @media (max-width: 768px) {

            th,
            td {
                padding: 4px 8px;
                font-size: 14px;
            }

            .qiu-item {
                width: 24px;
                height: 24px;
                line-height: 24px;
                font-size: 12px;
            }
        }
    </style>
</head>

<body>
    <div class="table-container">

        <div>
            <input type="text" id="input-period" placeholder="请输入一注双色球">
            <button id="btn-search">输入号码最高中奖</button><br>
            <span id="result">结果</span>
        </div>
        <table class="ssq_table">
            <thead>
                <tr>
                    <th rowspan="2">期号</th>
                    <th rowspan="2">开奖日期</th>
                    <th rowspan="2">开奖号码</th>
                    <th colspan="2">一等奖</th>
                    <th colspan="2">二等奖</th>
                    <th rowspan="2">销售额（元）</th>
                    <th rowspan="2">奖池金额（元）</th>
                    <th rowspan="2">开奖公告</th>
                </tr>
                <tr>
                    <th>注数</th>
                    <th>金额</th>
                    <th>注数</th>
                    <th>金额</th>
                </tr>
            </thead>
            <tbody id="datas">
                <tr data-alias="undefined" "="">
                <td>2025136</td><td>2025-11-25(二)</td><td>
                    <div class=" qiu">
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">8</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">10</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">14</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">23</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">28</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">32</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-blue">12</div>
    </div>
    </td>
    <td>43</td>
    <td>5467124</td>
    <td>101</td>
    <td>248593</td>
    <td>361,034,006</td>
    <td>2,583,189,299</td>
    <td><a href="/c/2025/11/25/637266.shtml" target="blank">详情</a></td>
    </tr>
    </tbody>
    </table>
    </div>


    <script src="./lottery_results.js">

    </script>



    <script>
        // 初始加载前50条数据
        let currentPage = 1;
        const pageSize = 50;
        const totalData = lotteryResults.length;

        // 生成表格行的函数
        function generateTableRow(item) {
            return `
            <tr data-alias="undefined" "">
                <td>${item["期号"]}</td><td>${item["开奖日期"]}</td><td>
                    <div class=" qiu">
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">${item["开奖号码"]["红球"][0]}</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">${item["开奖号码"]["红球"][1]}</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">${item["开奖号码"]["红球"][2]}</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">${item["开奖号码"]["红球"][3]}</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">${item["开奖号码"]["红球"][4]}</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-red">${item["开奖号码"]["红球"][5]}</div>
                    <div class="qiu-item qiu-item-small qiu-item-wqgg-zjhm-blue">${item["开奖号码"]["蓝球"]}</div>
                    </div>
                </td>
                <td>${item["一等奖注数"]}</td>
                <td>${item["一等奖金额"]}</td>
                <td>${item["二等奖注数"]}</td>
                <td>${item["二等奖金额"]}</td>
                <td>${item["销售额"]}</td>
                <td>${item["奖池金额"]}</td>
                <td><a href="${item["开奖公告"]}" target="blank">详情</a></td>
            </tr>
            `;
        }

        // 加载初始数据
        function loadInitialData() {
            const initialData = lotteryResults.slice(0, pageSize);
            document.querySelector("#datas").innerHTML = initialData.map(generateTableRow).join("");
        }

        // 加载更多数据
        function loadMoreData() {
            const startIndex = currentPage * pageSize;
            const endIndex = startIndex + pageSize;

            // 检查是否还有更多数据
            if (startIndex >= totalData) {
                window.removeEventListener('scroll', handleScroll);
                return;
            }

            const moreData = lotteryResults.slice(startIndex, endIndex);
            const newRows = moreData.map(generateTableRow).join("");

            // 追加新数据
            document.querySelector("#datas").insertAdjacentHTML('beforeend', newRows);
            currentPage++;
        }

        // 滚动事件监听
        function handleScroll() {
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
            const clientHeight = document.documentElement.clientHeight || window.innerHeight;

            // 当滚动到距离底部50px时加载更多
            if (scrollTop + clientHeight >= scrollHeight - 50) {
                loadMoreData();
            }
        }

        // 初始化
        loadInitialData();
        window.addEventListener('scroll', handleScroll);
    </script>
    <script>
        const inputPeriod = document.getElementById("input-period");
        const result = document.getElementById("result");
        document.getElementById("btn-search").addEventListener("click", function () {
            let bet;
            try {
                bet = parseInput(inputPeriod.value);
            } catch (e) {
                result.innerHTML = ` 输入错误: ${e.message}`;
                return;
            }
            const allMatches = {
                1: [], 2: [], 3: [], 4: [], 5: [], 6: []
            }; // 存储所有中奖记录
            const stats = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0 }; // 统计各等奖次数

            let bestMatch = null;  // { 期号, level, record }
            for (const record of lotteryResults) {
                const level = getPrizeLevel(record, bet);
                if (level !== null) {
                    // 找最高奖项（数字越小奖项越高）
                    if (!bestMatch || level < bestMatch.level) {
                        bestMatch = { 期号: record.期号, level, record };
                    }
                    allMatches[level].push({ 期号: record.期号, level, record });
                    stats[level]++;
                }
            }

            if (bestMatch) {
                const prizeNames = {
                    1: '一等奖',
                    2: '二等奖',
                    3: '三等奖',
                    4: '四等奖',
                    5: '五等奖',
                    6: '六等奖'
                };
                //console.log(`🎉 历史中过奖！最高奖项：${prizeNames[bestMatch.level]}，出现在第 ${bestMatch.期号} 期`);
                result.innerHTML = `🎉 历史中过奖！最高奖项：${prizeNames[bestMatch.level]}，出现在第 ${bestMatch.期号} 期
                <br/> 开奖号码：${bestMatch.record.开奖号码.红球.join(' ')} ${bestMatch.record.开奖号码.蓝球}`;

                for (let level = 1; level <= 6; level++) {
                    console.log(`  ${prizeNames[level]}：${stats[level]} 次`);
                }
                console.log(allMatches);
            } else {
                result.innerHTML = '😔 该注号码在所有历史开奖中从未中过任何奖项。';
            }
        })

        // 解析用户输入的一注双色球
        function parseInput(input) {
            const parts = input.trim().split(/\s+/);
            if (parts.length !== 7) {
                throw new Error('请输入7个号码（6个红球 + 1个蓝球），用空格分隔，例如：01 02 03 04 05 06 16');
            }

            let red = parts.slice(0, 6).map(n => n.padStart(2, '0'));
            const blue = parts[6].padStart(2, '0');

            // 验证范围
            const redNums = red.map(r => parseInt(r, 10));
            if (redNums.some(n => n < 1 || n > 33)) {
                throw new Error('红球必须在 01–33 范围内');
            }
            const blueNum = parseInt(blue, 10);
            if (blueNum < 1 || blueNum > 16) {
                throw new Error('蓝球必须在 01–16 范围内');
            }

            // 检查红球是否重复
            if (new Set(red).size !== 6) {
                throw new Error('红球不能重复');
            }

            // 排序红球（与历史数据一致）
            red = red.sort((a, b) => parseInt(a) - parseInt(b));

            return { red, blue };
        }

        // 判断中奖等级（根据双色球官方规则）
        function getPrizeLevel(draw, bet) {
            const redMatch = draw.开奖号码.红球.filter(r => bet.red.includes(r)).length;
            const blueMatch = draw.开奖号码.蓝球 === bet.blue;

            if (redMatch === 6 && blueMatch) return 1; // 一等奖
            if (redMatch === 6) return 2;               // 二等奖
            if (redMatch === 5 && blueMatch) return 3;  // 三等奖
            if (redMatch === 5 || (redMatch === 4 && blueMatch)) return 4; // 四等奖
            if (redMatch === 4 || (redMatch === 3 && blueMatch)) return 5; // 五等奖
            if (blueMatch) return 6;                    // 六等奖（仅蓝球）

            return null; // 未中奖
        }


    </script>
</body>

</html>